package com.selfmade.transferutil.http;

import android.util.Log;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.JsonRequest;
import com.selfmade.transferutil.app.MyApp;

import org.json.JSONObject;

/**
 * Created by Selfmade on 2017/7/23/0023.
 */

public class HttpRequest {

    private JSONObject postJson = null, getJson = null;

    public JSONObject getGetJson() {
        return getJson;
    }

    public JSONObject getPostJson() {
        return postJson;
    }
    public void httpJsonGet(String url) {
        Log.d("JsonGet请求：", "调用了");
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Log.d("JsonGet请求信息：", response.toString());
                getJson = response;
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("JsonGet请求出错：", error.getMessage(), error);
            }
        });
        MyApp.requestQueue.add(jsonObjectRequest);
        MyApp.requestQueue.start();
    }
    public void httpJsonPost(JSONObject jsonObject, String url) {
        Log.d("JsonPost请求：", "调用");
        JsonRequest<JSONObject> jsonRequest = new JsonObjectRequest(Request.Method.POST, url, jsonObject,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        postJson = response;
                        Log.d("HttpJsonPost请求信息", response.toString());
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("TAG_VolleyError", error.getMessage(), error);
            }
        });
        MyApp.requestQueue.add(jsonRequest);
        MyApp.requestQueue.start();
    }
}
